package com.masterclient.app.modules.firstpager.fragments.adapters;

import android.graphics.Paint;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.bumptech.glide.load.Transformation;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.eoner.baselibrary.utils.ScreenUtils;
import com.eoner.baselibrary.utils.ViewTransformUtil;
import com.eoner.commonbean.product.ProductMessage;
import com.masterclient.app.R;
import com.eoner.baselibrary.utils.Utils;

import jp.wasabeef.glide.transformations.RoundedCornersTransformation;

/**
 * @auther hjian
 * @date 2020/7/17.
 */
public class NewcommerProductAdapter extends BaseQuickAdapter<ProductMessage, BaseViewHolder> {

    public NewcommerProductAdapter() {
        super(R.layout.item_newcomer_product);
    }

    @Override
    protected void convert(BaseViewHolder helper, ProductMessage item) {

        ViewTransformUtil.glideImageView(mContext,item.getImage(),helper.getView(R.id.item_newcomer_img),
                new Transformation[]{new RoundedCornersTransformation(ScreenUtils.dp2px(7),0)},R.color.transparent);

        TextView price = helper.getView(R.id.item_newcomer_price);
        Utils.setDin(price, mContext);
        Utils.setDin(helper.getView(R.id.item_newcomer_unit), mContext);

        TextView item_newcomer_tag = helper.getView(R.id.item_newcomer_tag);

        String tag_name = null;
        if (item.getTags() != null && item.getTags().size() > 0 && item.getTags().get(0).getName() != null) {
            tag_name = item.getTags().get(0).getName();
            item_newcomer_tag.setText(tag_name);
            item_newcomer_tag.setVisibility(View.VISIBLE);
        } else {
            item_newcomer_tag.setVisibility(View.GONE);
        }

        price.setText(item.getPrice());

        helper.setText(R.id.item_newcomer_title, item.getTitle())
                .setGone(R.id.item_newcomer_daily_ll, !TextUtils.isEmpty(item.getDaily_price()))
                .setText(R.id.item_newcomer_daily_price, !TextUtils.isEmpty(item.getDaily_price())
                        ?"¥"+item.getDaily_price():"")
                .setGone(R.id.item_newcomer_official_ll, !TextUtils.isEmpty(item.getMarket_price()))
                .setText(R.id.item_newcomer_official_price, !TextUtils.isEmpty(item.getMarket_price())
                        ?"¥"+item.getMarket_price():"");

        ((TextView)(helper.getView(R.id.item_newcomer_official_price))).setPaintFlags(Paint.STRIKE_THRU_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG);

    }
}
